#!/bin/sh
# Sets up Ubuntu 20.04 from bare-bones installation 
# Comment out what you don't need or run line-by-line, manually
sudo apt-get -qq update && \
    DEBIAN_FRONTEND=noninteractive \
    sudo apt-get -qq install -y cmake make git vim gcc g++ gfortran software-properties-common wget gnupg-agent \
            2to3 python3-pip python3-matplotlib python3-numpy jupyter gnuplot-qt valgrind kcachegrind graphviz \
            gv likwid \
            mpich libmpich-dev \
            openmpi-bin openmpi-doc libopenmpi-dev

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 30 \
                         --slave   /usr/bin/pip    pip    /usr/bin/pip3

# Installing latest GCC compiler (version 10)
sudo apt-get -qq install -y gcc-10 g++-10 gfortran-10

sudo update-alternatives \
      --install /usr/bin/gcc      gcc      /usr/bin/gcc-9       80 \
      --slave   /usr/bin/g++      g++      /usr/bin/g++-9          \
      --slave   /usr/bin/gfortran gfortran /usr/bin/gfortran-9     \
      --slave   /usr/bin/gcov     gcov     /usr/bin/gcov-9
sudo update-alternatives \
      --install /usr/bin/gcc      gcc      /usr/bin/gcc-10      90 \
      --slave   /usr/bin/g++      g++      /usr/bin/g++-10         \
      --slave   /usr/bin/gfortran gfortran /usr/bin/gfortran-10    \
      --slave   /usr/bin/gcov     gcov     /usr/bin/gcov-10
sudo chmod u+s /usr/bin/update-alternatives

# Installing Intel compilers since they give the best vectorization among compiler vendors
# Also installing Intel Advisor to look at vectorization performance
wget -q https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo rm -f GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo chmod 777 /etc/apt/sources.list.d/ 
sudo echo "deb https://apt.repos.intel.com/oneapi all main" >> /etc/apt/sources.list.d/oneAPI.list
sudo echo "deb [trusted=yes arch=amd64] https://repositories.intel.com/graphics/ubuntu bionic main" >> /etc/apt/sources.list.d/intel-graphics.list
sudo chmod 755 /etc/apt/sources.list.d/ 
sudo apt-get -qq update && \
sudo apt-get -qq install -y \
             intel-hpckit-getting-started \
             intel-oneapi-common-vars \
             intel-oneapi-common-licensing \
             intel-oneapi-dev-utilities \
             intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic \
             intel-oneapi-ifort \
             intel-oneapi-advisor

# Needed libraries for Intel Advisor graphics user interface
sudo apt-get -qq install -y libgtk2.0-0 libxxf86vm1 libsm6 libnss3 libnss3 libx11-xcb1 libxtst6 \
            libasound2 libatk-bridge2.0-0

sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/*

echo "Add source /opt/intel/oneapi/setvars.sh to dotfile"
source /opt/intel/oneapi/setvars.sh

#make clean
#make
